<template>
  <view class="shopping-wrapper">
    <!-- 登录弹窗 -->
    <loginDialog
      @on-off="getHome"
      @on-make="headelMake"
      :indicate="userLoginDialog"
    >
    </loginDialog>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";
import loginDialog from "@/components/login/index.vue";
import {
  get1688NavParamsApi,
} from "@/api/shopping";
import {  onTabItemTap } from "@dcloudio/uni-app";
const userLoginInfo = ref("");
const userLoginDialog = ref(false);
onTabItemTap(async (item) => {
  const { text } = item;
  if (text === "荣耀权益") {
    userLoginInfo.value = uni.getStorageSync("token");
    /*if (!userLoginInfo.value) {
      userLoginDialog.value = true;
    } else {*/
      procedureJump();
    // }
  }
});
function getHome() {
  uni.switchTab({
    url: "/pages/index/index",
  });
}
function headelMake() {
  userLoginDialog.value = false;
  userLoginInfo.value = uni.getStorageSync("token");
  procedureJump();
}
async function procedureJump() {
  const res = await get1688NavParamsApi();
  const { code, data } = res;
  // uni.navigateToMiniProgram({
  //   appId:'wx90337e70657a6d17',
  //   path: 'pages/index/index',
  //   extraData: {}
  // })
  // #ifdef H5 || APP-PLUS
  openMiniProgram(data.code, data.phone);
  // #endif

  // #ifdef  MP-WEIXIN
  // uni.openEmbeddedMiniProgram({
  uni.navigateToMiniProgram({
    appId: "wx90337e70657a6d17",
    path: "pages/index/index",
    envVersion: "release",
    extraData: {
      authCode: data.code,
      mobile: data.phone,
    },
  });
  // #endif
}
function openMiniProgram(code, phone) {
  let data = {
    targetId: "gh_f19b19cb63b7",
    paramsStr: `pages/index/index?mobile=${phone}&authCode=${code}`,
    // paramsStr: `pages/index/index`,
    type: 0,
    // type: 2,//体验版
  };
  window.mobile.jsCallOpenSmallProgram(JSON.stringify(data));
}
</script>

<style lang="less" scoped>
</style>
